package com.itheima.dao;

import com.itheima.pojo.BlogSort;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

public interface BlogSortMapper extends Mapper<BlogSort> {

    //5   置顶分类
    @Select("SELECT * from t_blog_sort ORDER BY sort DESC")
    int stick();
    //查询最大的sort字段值

    @Select("SELECT MAX(sort) FROM t_blog_sort")
    int findMaxSort();

    //6 通过引用量排序博客分类
    @Select("SELECT\n" +
            "\tcount( b.blog_sort_uid ) st,\n" +
            "\ts.*\n" +
            "FROM\n" +
            "\tt_blog b,\n" +
            "\tt_blog_sort s\n" +
            "WHERE b.blog_sort_uid=s.uid GROUP BY s.uid ORDER BY st DESC\n")
    int  blogSortByCite();


    //7 通过点击量排序博客分类
    @Select("SELECT * from t_blog_sort ORDER BY click_count DESC")
    int  blogSortByClickCount();

    /**
     * 根据uid获取sortName
     * @param uid
     * @return
     */
    @Select("select sort_name from t_blog_sort where uid=#{uid}")
    String getSortNameByUid(@Param("uid") String uid);

    /**
     * 根据uid获取sort对象
     * @param uid
     * @return
     */
    @Select("select * from t_blog_sort where uid=#{uid}")
    BlogSort getBlogSortByUid(@Param("uid") String uid);

}
